import time

from selenium import webdriver
from zoukao3.Base.Base import Base
from selenium.webdriver.common.by import By
class Page(Base):
    # 点击登录按钮
    login_loc=(By.LINK_TEXT,'登录')
    # 输入用户名
    username_loc=(By.NAME,'username')
    # 输入密码
    password_loc=(By.NAME,'password')
    # 点击登录
    loginbtn_loc=(By.CLASS_NAME,'finish-btn')
    # 断言欢迎回来
    dy1_loc=(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
    # 首页
    goods_loc=(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a')
    # 搜索
    sreach_loc=(By.CLASS_NAME,'search-input')
    sreachbtn_loc=(By.CLASS_NAME,'search-input-btn')
    # 搜索结果
    dy2_loc=(By.XPATH,'/html/body/div[4]/a[2]')
    # 商品详情
    shop_loc=(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li/div[1]/span/a/img')
    # 立即购买
    buy_loc=(By.ID,'buy-cart')
    # 下一步
    next_loc=(By.ID,'order-button')
    print('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')

    def login(self):
        self.click(self.login_loc)
    def username(self):
        self.send_keys(self.username_loc,'18986670716')
    def password(self):
        self.send_keys(self.password_loc,'a123456')
    def loginbtn(self):
        self.click(self.loginbtn_loc)
    def dy1(self):
        return self.text(self.dy1_loc)
    def goods(self):
        self.click(self.goods_loc)
    def sreach(self):
        self.send_keys(self.sreach_loc,'钢铁侠')
    def sreachbtn(self):
        self.click(self.sreachbtn_loc)
    # 断言搜索的结果
    def dy2(self):
        return self.text(self.dy2_loc)
    def shop(self):
        self.click(self.shop_loc)
    def buy(self):
        self.click(self.buy_loc)
    def next(self):
        self.click(self.next_loc)

#     业务逻辑
    def luoji_01(self):
        self.open_url('http://10.59.9.12:7001/')
        self.login()
        self.username()
        self.password()
        time.sleep(8)
        self.loginbtn()
        time.sleep(5)
        print(self.dy1())
        assert  '欢迎回来，18986670716' in self.dy1()
        self.goods()
        self.sreach()
        self.sreachbtn()
        try:
            print(self.dy2())
            assert '搜索结果' == self.dy2()
            time.sleep(2)
            self.shop()
            self.buy()
            self.next()
            time.sleep(5)
        except Exception as e:
            print('数据库连接超时-404')
            print(e)





